//
//  UIImage+ClipIconImage.m
//  音乐播放器2
//
//  Created by LeungChaos on 15/12/26.
//  Copyright © 2015年 liang. All rights reserved.
//

#import "UIImage+ClipIconImage.h"

@implementation UIImage (ClipIconImage)

+ (id)clipIconViewWithImageName:(NSString *)imageName withSize:(CGSize)size {
    UIImage *oldImage = [UIImage imageNamed:imageName];
    
    UIGraphicsBeginImageContext(size);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSaveGState(context);
    
    CGContextAddEllipseInRect(context, CGRectMake(3, 3, size.width *0.6,size.height*0.6));
    
    CGContextClip(context);
    
    [oldImage drawInRect:CGRectMake(3, 3, size.width * 0.6, size.height *0.6)];
    
    CGContextRestoreGState(context);

    CGContextSetRGBStrokeColor(context, 0.5, 1, 1, 1);
    
    CGContextSetLineWidth(context, 3);
    
    CGContextStrokeEllipseInRect(context, CGRectMake(3, 3, size.width * 0.6, size.height * 0.6));
    
    CGContextStrokePath(context);
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
}

@end
